package com.tanhua.server.controller;

import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.dto.ReplyDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    //今日佳人
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaService.selectToDayBest();
        return ResponseEntity.ok(vo);
    }

    //分页推荐朋友
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto) {
        PageResult pageResult = tanhuaService.recommendation(dto);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 查询佳人信息
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity findByBest(@PathVariable("id") Long bestId) {
        TodayBest best = tanhuaService.findByBest(bestId);
        return ResponseEntity.ok(best);
    }


    /**
     * 查看陌生人的问题
     *
     * @param userId
     * @return
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {

        String question = tanhuaService.findStrangerQuestions(userId);
        return ResponseEntity.ok(question);
    }

    /**
     * 回复问题
     *
     * @param replyDto
     * @return
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestBody ReplyDto replyDto) {
        //获取回复的id和回复信息
        String reply = replyDto.getReply();
        Long userId = Long.valueOf(replyDto.getUserId().toString());
        tanhuaService.replyQuestions(reply, userId);
        return ResponseEntity.ok(null);
    }

    /**
     * 探花-推荐用户
     *
     * @return
     */
    @GetMapping("/cards")
    public ResponseEntity CardsList() {
        List<TodayBest> list = tanhuaService.cardsList();
        return ResponseEntity.ok(list);
    }

    //喜欢右滑
    @GetMapping("{id}/love")
    public ResponseEntity likeUser(@PathVariable("id") Long likeUserId) {
        tanhuaService.likeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    //不喜欢左滑
    @GetMapping("{id}/unlove")
    public ResponseEntity<Void> notLikeUser(@PathVariable("id") Long likeUserId) {
        tanhuaService.notLikeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 搜附近
     */
    @GetMapping("/search")
    public ResponseEntity<List<NearUserVo>> queryNearUser(String gender,
                                                          @RequestParam(defaultValue = "2000") String distance) {
        List<NearUserVo> list = tanhuaService.queryNearUser(gender, distance);
        return ResponseEntity.ok(list);
    }


}
